package main

import (
	"database/sql"
	"io"
	"log"
	"net/http"
	"os"

	_ "github.com/mattn/go-sqlite3"
)

func main() {
	testHttp()
	testSqlite()

}

func testHttp() {
	log.Println("test https")
	resp, err := http.Get("https://api-pro.000982.net")
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()
	if _, err := io.Copy(os.Stdout, resp.Body); err != nil {
		log.Fatal(err)
	}
	println()
}

func testSqlite() {
	db, err := sql.Open("sqlite3", "./ndk_test.db")
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()
	db.Exec("CREATE TABLE IF NOT EXISTS users(name STRING PRIMARY KEY NOT NULL,age INT NOT NULL)")
	res, err := db.Exec("INSERT INTO users(name,age) VALUES(?,?)", "Mike", 36)
	if err == nil {
		log.Println(res.RowsAffected())
	}
	rows, err := db.Query("SELECT * FROM users")
	if err != nil {
		log.Fatal(err)
	}
	for rows.Next() {
		var name string
		var age int
		err := rows.Scan(&name, &age)
		if err != nil {
			log.Fatal(err)
		}
		log.Printf("name:%s, age:%d \n", name, age)
	}
}
